package com.stefanini.pe.bbva.mbl.in.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.stefanini.pe.bbva.mbl.carga.in.to.Corporativa;
import com.stefanini.pe.bbva.mbl.carga.in.to.CorporativaKey;
import com.stefanini.pe.bbva.mbl.in.dao.iface.CorporativaDAO;

import org.apache.log4j.Logger;

public class CorporativaDAOImpl extends SqlMapClientDaoSupport implements CorporativaDAO {
	private static Logger logger = Logger.getLogger(CorporativaDAOImpl.class);

    public CorporativaDAOImpl() {
        super();
    }

    public int deleteByPrimaryKey(CorporativaKey key) {
    	int rows = 0;
    	
    	logger.info("inicio");
    	
        rows = getSqlMapClientTemplate().delete("CORPORATIVA.ibatorgenerated_deleteByPrimaryKey", key);
        
        logger.info("Fin");
        
        return rows;
    }

    public void insert(Corporativa record) {
    	logger.info("Inicio");
    	
        getSqlMapClientTemplate().insert("CORPORATIVA.ibatorgenerated_insert", record);
        
        logger.info("Fin");
    }

    public void insertSelective(Corporativa record) {
    	logger.info("Inicio");
    	
        getSqlMapClientTemplate().insert("CORPORATIVA.ibatorgenerated_insertSelective", record);
        
        logger.info("Fin");
    }

    public Corporativa selectByPrimaryKey(CorporativaKey key) {
        Corporativa record = null;
        
        logger.info("Inicio");
        
        record = (Corporativa) getSqlMapClientTemplate().queryForObject("CORPORATIVA.ibatorgenerated_selectByPrimaryKey", key);
        
        logger.info("Fin");
        
        return record;
    }

    public int updateByPrimaryKeySelective(Corporativa record) {
        int rows = 0;
        
        logger.info("Inicio");
        
        rows = getSqlMapClientTemplate().update("CORPORATIVA.ibatorgenerated_updateByPrimaryKeySelective", record);
        
        logger.info("Fin");
        
        return rows;
    }

    public int updateByPrimaryKey(Corporativa record) {
        int rows = 0;
        
        logger.info("Inicio");
        
        rows = getSqlMapClientTemplate().update("CORPORATIVA.ibatorgenerated_updateByPrimaryKey", record);
        
        logger.info("Fin");
        
        return rows;
    }
    
    public List selectByCriteria(Corporativa record){
    	List records = null;
    	
    	logger.info("Inicio");
    	
    	records = (List) getSqlMapClientTemplate().queryForList("CORPORATIVA.ibatorgenerated_selectByCriteria",record);
    	
    	logger.info("Fin");
    	
		return records;
    }
    
    public List selectByCriteriaLit_Lar(Corporativa record){
    	List records = null;
    	
    	logger.info("Inicio");
    	
    	records = (List) getSqlMapClientTemplate().queryForList("CORPORATIVA.ibatorgenerated_selectByCriteria",record);
    	
    	logger.info("Fin");
    	
		return records;
    }
    
    public List selectTabs() {
    	List records = null;    	
    	
    	records = (List) getSqlMapClientTemplate().queryForList("CORPORATIVA.ibatorgenerated_selectTabs");
    	
    	return records;
    }

    public List selectByTab(Corporativa record) {
    	List records = null;
    	
    	records = (List) getSqlMapClientTemplate().queryForList("CORPORATIVA.ibatorgenerated_selectByTab", record);
    	
    	return records;
    }
    
    public List selectMaxElemByTab(Corporativa record) {
    	List records = null;
    	
    	logger.info("Inicio");
    	
    	records = (List) getSqlMapClientTemplate().queryForList("CORPORATIVA.ibatorgenerated_selectMaxElemByTab", record);
    	
    	logger.info("Fin");
    	
    	return records;
    }
    
    public String actualizarNombreDirectorio(String nomDirAnt, String nomDirNuevo) {
		HashMap map = new HashMap();
		String retorno = null;

		logger.info("Inicio");
		
		map.put("pi_nom_dir_ant", nomDirAnt);
		map.put("pi_nom_dir_nuevo", nomDirNuevo);

		this.getSqlMapClientTemplate().queryForObject("CORPORATIVA.sp_renombra_directorio", map);

		logger.info("Fin");

		return retorno;
	}
}